package com.falcon.controller.toolkit;

import com.falcon.mvc.base.IBaseController;
import com.falcon.mvc.domain.BaseResponse;
import com.falcon.domain.req.GenApiTsRequest;
import com.falcon.service.IVbenGeneratorService;
import com.swan.core.utils.ClassUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ClassUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Slf4j
@RestController
@RequestMapping("/toolkit/genVben")
@Tag(name = "5.Vben 框架代码生成", description = "生成 api.ts、xx.vue等文件")
public class GenVbenController implements IBaseController {

    @Autowired
    private IVbenGeneratorService generatorService;



    @Operation(summary = "生成api.ts")
    @PostMapping("/apiTs")
    public BaseResponse<Boolean> apiTs(@Valid @RequestBody GenApiTsRequest request) {

        Class<String> aClass = ClassUtil.forName(request.getCanonicalName(), ClassUtils.getDefaultClassLoader());
        this.generatorService.generateApiTs(aClass);

        return BaseResponse.success(true);
    }

    @Operation(summary = "生成 domain类型")
    @PostMapping("/domain")
    public BaseResponse<Boolean> domain(String canonicalName) {

        this.generatorService.generateDomain(canonicalName);

        return BaseResponse.success(true);
    }



}

